package com.kingmed.kmss.admin.modules.sys.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kingmed.kmss.admin.modules.sys.model.SysOpenUrl;
import com.kingmed.kmss.admin.modules.sys.service.ISysOpenUrlService;
import com.kingmed.kmss.common.vo.CommonPage;
import com.kingmed.kmss.common.vo.CommonResponse;
import com.kingmed.kmss.common.vo.CommonResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 对外授权接口清单
 * 
 * @author Sys
 * @date 2022-12-16
 */
@RestController
@RequestMapping("/sys/open/url")
@Api(tags = "sys对外授权接口清单")
public class SysOpenUrlController
{
    @Autowired
    private ISysOpenUrlService sysOpenUrlService;

    /**
     * 查询对外授权接口清单列表
     */
    @ApiOperation("查询对外授权接口清单列表")
    @GetMapping("/list")
    public CommonResponse<CommonPage<SysOpenUrl>> list(SysOpenUrl SysOpenUrl,
                                                       @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                       @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
    {
        Page<SysOpenUrl> list = sysOpenUrlService.list(SysOpenUrl, pageNum, pageSize);
        return CommonResponseHelper.success(CommonPage.restPage((list)));
    }

    /**
     * 获取对外授权接口清单详细信息
     */
    @ApiOperation("获取对外授权接口清单详细信息")
    @GetMapping(value = "/{urlId}")
    public CommonResponse<SysOpenUrl> getInfo(@PathVariable("urlId") String urlId)
    {
        return CommonResponseHelper.success(sysOpenUrlService.selectSysOpenUrlByUrlId(urlId));
    }

    /**
     * 新增对外授权接口清单
     */
    @ApiOperation("新增对外授权接口清单")
    @PostMapping("/add")
    public CommonResponse<Boolean> add(@RequestBody SysOpenUrl SysOpenUrl)
    {
        return CommonResponseHelper.success(sysOpenUrlService.insertSysOpenUrl(SysOpenUrl));
    }

    /**
     * 修改对外授权接口清单
     */
    @ApiOperation("修改对外授权接口清单")
    @PutMapping("/edit")
    public CommonResponse<Boolean> edit(@RequestBody SysOpenUrl SysOpenUrl)
    {
        return CommonResponseHelper.success(sysOpenUrlService.updateSysOpenUrl(SysOpenUrl));
    }

    /**
     * 删除对外授权接口清单
     */
    @ApiOperation("删除对外授权接口清单")
	@DeleteMapping("/remove/{urlIds}")
    public CommonResponse<Boolean> remove(@PathVariable String[] urlIds)
    {
        return CommonResponseHelper.success(sysOpenUrlService.deleteSysOpenUrlByUrlIds(urlIds));
    }
}
